package com.orange.notificationsummary;

import java.util.List;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.orange.notificationsummary.event.pil.defaultimpl.BaseEvent;
import com.orange.notificationsummary.utils.LogHelper;

public class SummaryListAdapter extends BaseAdapter {
	private static final String	TAG	= "SummaryListAdapter";

	private Context				mContext;
	public List<BaseEvent>		mEvents;

	public SummaryListAdapter(Context context, List<BaseEvent> events) {
		super();
		this.mContext = context;
		this.mEvents = events;
	}

	@Override
	public int getCount() {
		int count = 0;
		if (mEvents != null) {
			count = mEvents.size();
		}
		return count;
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = null;
		if (convertView == null) {
			LayoutInflater flater = LayoutInflater.from(mContext);
			v = flater.inflate(R.layout.summary_event_layout, null);
		} else {
			v = convertView;
		}

		if (mEvents != null && !mEvents.isEmpty()) {
			LogHelper.v(TAG, "getView. events: " + mEvents.size());
			BaseEvent event = mEvents.get(position);
			if (!TextUtils.isEmpty(event.event_mms_subject)
					&& TextUtils.isEmpty(event.event_mms_content)) {
				event.event_mms_content = mContext
						.getString(R.string.no_message);
				;
			}

			v = event.getView(mContext, v);
		}
		return v;
	}
}
